<template>
  <div>
    <div style="margin: 10px 0">
      <!--      <el-upload action="http://localhost:9090/file/upload" :show-file-list="false" :on-success="handleFileUploadSuccess" style="display: inline-block">-->
      <!--        <el-button type="primary" class="ml-5">上传文件 <i class="el-icon-top"></i></el-button>-->
      <!--      </el-upload>-->
      <el-popconfirm
          class="ml-5"
          confirm-button-text='确定'
          cancel-button-text='我再想想'
          icon="el-icon-info"
          icon-color="red"
          title="您确定批量删除这些数据吗？"
          @confirm="delBatch"
      >
        <el-button type="danger" slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>
      </el-popconfirm>

    </div>
    <el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="orderId" label="orderId" width="80"></el-table-column>
<!--      <el-table-column prop="userName" label="用户名"></el-table-column>-->
      <el-table-column prop="pbssName" label="投放点名称"></el-table-column>
      <el-table-column prop="pbName" label="充电宝名称"></el-table-column>
      <el-table-column prop="phone" label="手机号"></el-table-column>
      <el-table-column prop="payStyle" label="支付方式" :formatter="formatBoolean" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.payStyle===true">
            免押金支付
          </el-tag>
          <el-tag type="warning" v-if="scope.row.payStyle===false">
            直接支付
          </el-tag>

        </template>
      </el-table-column>
      <el-table-column prop="orderstatus" label="订单状态" :formatter="formatBoolean2" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.orderStatus===true">
            已完成
          </el-tag>
          <el-tag type="danger" v-if="scope.row.orderStatus===false">
            未完成
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="开始时间"></el-table-column>
      <el-table-column prop="endTime" label="结束时间"></el-table-column>

      <el-table-column label="操作"  width="200" align="center">
        <template slot-scope="scope">
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗？"
              @confirm="del(scope.row.orderId)"
          >
            <el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>







  </div>
</template>

<script>
export default {
  name: "Pbss",
  data() {
    return {
      tableData: [],
      userName: '',
      orderId:'',
      multipleSelection: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      dialogFormVisible:false,
      form:{},
      options:[],
      pbNames:[],
      user: localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}
    }
  },
  created() {
    this.load(),
        this.getPbssName()

  },
  methods: {
    load() {
      this.request.get("/user/order/historyPage", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          userName:this.userName,
          orderId:this.orderId

        }
      }).then(res => {

        if(res.code==='200'){
          this.tableData = res.data.records
          this.total = res.data.total
        }else {
          // this.$message.error(res.msg)
        }

      })
    },
    save(){
      this.request.post("/order/save",this.form).then(res=>{
        if (res){
          this.$message.success("保存成功！")
          this.dialogFormVisible=false;
          this.load()
        }else {
          this.$message.error("保存失败")
        }
      })
    },
    changeEnable(row) {
      this.request.post("/order/update", row).then(res => {
        if (res.code === '200') {
          this.$message.success("操作成功")
        }
      })
    },
    del(id) {
      this.request.delete("/order/"+id).then(res => {
        if (res.code === '200') {
          this.$message.success("删除成功")
          this.load()
        } else if(res.code==='401'){

        }else {
          this.$message.error("删除失败")
        }
      })
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    delBatch() {
      let ids = this.multipleSelection.map(v => v.orderId)  // [{}, {}, {}] => [1,2,3]
      this.request.post("/order/del/batch",ids).then(res => {
        if (res.code === '200') {
          this.$message.success("批量删除成功")
          this.load()
        } else {
          // this.$message.error("批量删除失败")
        }
      })
    },
    reset() {
      this.userName = "",
          this.orderId=''
      this.load()
    },
    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    handleAdd(){
      this.dialogFormVisible=true,
          this.form={}

    },
    handleEdit(row){
      this.dialogFormVisible=true,
          this.form=row
    },
    formatBoolean: function (row) {
      let ret = ''
      if (row.payStyle === true) {
        ret = "免押金支付" //根据自己的需求设定
      } else {
        ret = "直接支付"
      }
      return ret;
    },
    formatBoolean2: function (row) {
      let ret = ''
      if (row.orderStatus === true) {
        ret = "已完成" //根据自己的需求设定
      } else {
        ret = "未完成"
      }
      return ret;
    },
    getPbssName(){
      this.request.get("Pbss/pbssName").then(res=>{
        console.log(res)
        this.options=res.data
      })
      // handleFileUploadSuccess(res) {
      //   console.log(res)
      //   this.load()
      // },
      // download(url) {
      //   window.open(url)
      // }
    },
    getPbName(){
      this.request.get("Pb/pbName").then(res=>{
        this.pbNames=res.data
      })
    }
  }
}
</script>

<style scoped>

</style>